package com.shujia.mllib

import org.apache.spark.ml.classification.LogisticRegressionModel
import org.apache.spark.ml.linalg
import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.sql.SparkSession

object Demo3Model {

  def main(args: Array[String]): Unit = {

    val spark: SparkSession = SparkSession.builder()
      .master("local")
      .appName("person")
      .config("spark.sql.shuffle.partitions", 2)
      .getOrCreate()


    /**
      * 模型使用
      *
      */

    val model: LogisticRegressionModel = LogisticRegressionModel.load("spark/data/model")


    /**
      *
      * 使用模型进行预测
      *
      * 1:4.2 2:3.0 3:2.4 4:97.3 5:57.7 6:58.5 7:89
      *
      * 1 1:5.7 2:4.3 3:3.5 4:130.1 5:85.9 6:84.0 7:65
      */

    //    val vector: linalg.Vector = Vectors.dense(Array(4.2, 3.0, 2.4, 97.3, 57.7, 58.5, 89))
    val vector: linalg.Vector = Vectors.dense(Array(5.7, 4.3, 3.5, 130.1, 85.9, 84.0, 65))

    //预测
    val d: Double = model.predict(vector)

    println(d)

  }

}
